package com.hq.fxh.No2_BBS.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hq.fxh.Modle.PlateSoreModle;
import com.hq.fxh.R;
import com.hq.fxh.Receiver.ListCallBack;

import java.util.List;

/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :
 * @Created 2017/8/18
 * @Email xlwenhao1858@sina.com
 */


public class Ladapter_PlateSort extends BaseAdapter {
    List<PlateSoreModle.DataBean> data;
    ListCallBack listCallBack;

    public Ladapter_PlateSort(ListCallBack listCallBack) {
        this.listCallBack = listCallBack;
    }

    @Override
    public int getCount() {
        return data == null ? 0 : data.size();
    }

    @Override
    public PlateSoreModle.DataBean getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View convertView, ViewGroup parent) {
        View view = convertView;
        ViewHolder viewHolder = null;
        if (view == null || !(view.getTag() instanceof ViewHolder)) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.text_list_item, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.textListPlateName.setText(data.get(i).getCategory());
        viewHolder.textListPlateName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listCallBack.onCall(view, i, data.get(i));
            }
        });
        return view;
    }

    public void setData(List<PlateSoreModle.DataBean> data) {
        this.data = data;
    }

    static class ViewHolder {
        protected TextView textListPlateName;
        protected LinearLayout layoutListPlateName;

        ViewHolder(View rootView) {
            initView(rootView);
        }

        private void initView(View rootView) {
            textListPlateName = (TextView) rootView.findViewById(R.id.text_List_PlateName);
            layoutListPlateName = (LinearLayout) rootView.findViewById(R.id.layout_List_PlateName);
        }
    }
}
